/**
 * 数组分块
 * @param arr
 * @param size
 * @returns {Array}
 * Array.push()
 * Array.slice()
 * chunk([1,2,3,4,5],2)=[[1,2],[3,4],[5]];
 */

function chunk(arr, size) {
    // 请把你的代码写在这里
    var arr2 = [];
    for(var i=0;i<arr.length;i+=size){
        arr2.push(arr.slice(i,i+size));
    }
    return arr2;
}

chunk(["a", "b", "c", "d"], 2);


const chunk2 = (arr, size) =>
    Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
        arr.slice(i * size, i * size + size)
    );